# Maintainer: Manuel Naranjo <naranjo.manuel@gmail.com>

_pyname=psutil
_realname=${_pyname}
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.9.5
pkgrel=2
pkgdesc="A cross-platform process and system utilities module for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/giampaolo/psutil"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('staticlibs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/giampaolo/psutil/archive/release-${pkgver}.tar.gz"
        "0001-mingw-fixes-without-loadlib.patch")
sha256sums=('fba07e5d76e129ee1a374ea911e9bfc4161636260e33d055abb2b426ed182429'
            'f6570b1e84e9e393d0be69ddf02af0f5e496a00587f98c32d8cca7144a6bc8c4')

prepare() {
  cd "${srcdir}"/${_realname}-release-${pkgver}
  patch -p1 -i "${srcdir}/0001-mingw-fixes-without-loadlib.patch"

  cd ${srcdir}
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-release-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
